
import { VuexModule, Module, Action, Mutation, getModule, MutationAction } from 'vuex-module-decorators';
import store from '@/store';
import servers from '@/servers/index'

export interface publicAPIState {
  getAreaDictList: any[]

}
// 公共方法
@Module({ dynamic: true, store, name: 'publicAPI', namespaced: true })
class publicAPI extends VuexModule implements publicAPIState {
  // state

  public smsAccount: { account: string, password: string } = {
    account: "bdfk",
    password: "Lnsoft@1998"
  }//sms用户信息
  public stationTreeList: any[] = []//字典-变电站树图
  public pointerTypeList: any[] = []//字典-点位类型
  public getAreaDictList = []//字典-获取区域字典
  public stationList: any[] = []//字典-下拉框变电站
  public queryTypesList: any = []//字典-下拉框监测类型
  public queryAlermStatusList: any = []//字典-下拉框报警状态
  public queryCitysList: any = []//字典-下拉框所属地市
  public querySystemsList: any = []//字典-下拉框所属系统
  public AlarmSourceList: any = []//字典-下拉框告警来源

  /*********************** FanYu ***************************/
  public CompanyList: any = []    // 字典-下拉框单位名称
  public VoltageList: any = []    // 字典-下拉框变电站电压等级
  public SubstationList: any = [] // 字典-下拉框变电站
  public TeamList: any = []       // 字典-下拉框运维班组
  public DeviceTypeList: any = []  // 字典-下拉框设备类型
  public queryHasDataStationsList: any = [] //下拉框有数据变电站

  public pointType: any = {};                      //初始化字典
  querySubSystemList = []

  // 初始化
  @MutationAction({})
  async init() {
    return {
      stationTreeList: [],
      getAreaDictList: [],
      stationList: [],
      queryAlermStatusList: [],
      queryCitysList: [],
      querySystemsList: [],
      AlarmSourceList: [],
      CompanyList: [],
      VoltageList: [],
      SubstationList: [],
      TeamList: [],
      DeviceTypeList: [],
      queryHasDataStationsList: [],
    }
  }

  // 初始化字典
  @MutationAction({ mutate: ['pointType'] })
  async setPointer() {
    var obj: any = await (servers as any)
      .getPointerTypeDict({ data: {} }).then((res: any) => {
        // console.log("222222222222222222:",res.data);
        if (res.data) {
          let xtTypeObj = {}
          let sbTypeObj = {}
          let dwTypeObj = {}
          let data = res.data;
          data.forEach(v => {
            xtTypeObj[v.XTBM] = {
              xtName: v.XTMC,
              xtValue: v.XTBM
            }
            sbTypeObj[v.SBLX] = {
              xtName: v.XTMC,
              xtValue: v.XTBM,
              sbValue: v.SBLX,
              sbName: v.SBMC,
            }
            dwTypeObj[v.DWLX] = {
              xtName: v.XTMC,
              xtValue: v.XTBM,
              sbValue: v.SBLX,
              sbName: v.SBMC,
              dwValue: v.DWLX,
              dwName: v.DWMC,
            }
          })
          let obj = { xtTypeObj, sbTypeObj, dwTypeObj }
          // console.log("33333333333333333:",obj);
          return obj
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { pointType: obj }
  }


  // 下拉框单位名称
  @MutationAction({ mutate: ['CompanyList'] })
  async setCompanyList() {
    var list: any = await (servers as any)
      .getQueryDw({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { CompanyList: list }
  }

  // 下拉框变电站电压等级
  @MutationAction({ mutate: ['VoltageList'] })
  async setVoltageList() {
    var list: any = await (servers as any)
      .getQueryDydj({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { VoltageList: list }
  }

  // 下拉框变电站
  @MutationAction({ mutate: ['SubstationList'] })
  async setSubstationList() {
    var list: any = await (servers as any)
      .getQueryStations({ data: {} }).then((res: any) => {
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { SubstationList: list }
  }

  // 下拉框运维班组
  @MutationAction({ mutate: ['TeamList'] })
  async setTeamList() {
    var list: any = await (servers as any)
      .getQueryWhbz({ data: {} }).then((res: any) => {
        // console.log("下拉框运维班组:",res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { TeamList: list }
  }

  // 下拉框设备类型
  @MutationAction({ mutate: ['DeviceTypeList'] })
  async setDeviceTypeList() {
    var list: any = await (servers as any)
      .getDeviceTypePublic({ data: {} }).then((res: any) => {
        // console.log("下拉框设备类型:",res.data);
        return res.data
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { DeviceTypeList: list }
  }
  /***********************FanYu ***************************/

  //变电站树图
  @MutationAction({ mutate: ['stationTreeList'] })
  async setstationTreeList(data) {
    var list: any = await (servers as any)
      .getStationMenuTree({ data }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log("88888888888888888888:",list);
    return { stationTreeList: list }
  }

  //获取点位类型 传一个type 设备类型=>1：辅控设备，2：主设备，3：在线监测设备 { type: 3 }
  @MutationAction({ mutate: ['pointerTypeList'] })
  async getPointerType(params) {
    var list: any = await (servers as any)
      .getPointerType({ data: params }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { pointerTypeList: list }
  }

  //获取区域字典
  @MutationAction({ mutate: ['getAreaDictList'] })
  async getAreaDict() {
    var list: any = await (servers as any)
      .getAreaDict({ data: {} }).then((res: any) => {
        // console.log(res);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);

      });
    // console.log(list);
    return { getAreaDictList: list }
  }
  //获取告警来源
  @MutationAction({ mutate: ['AlarmSourceList'] })
  async getAlarmSource() {
    var list: any = await (servers as any)
      .getAlarmSource({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }

      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { AlarmSourceList: list }
  }

  //下拉框变电站
  @MutationAction({ mutate: ['stationList'] })
  async queryStations() {
    var list: any = await (servers as any)
      .queryStations({ data: {} }).then((res: any) => {
        // console.log(res);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { stationList: list }
  }

  //下拉框监测类型 传一个type 辅控实时还是主设备监测类型,可用值:辅控fk,主设备zsb { type: '辅控fk' }
  @MutationAction({ mutate: ['queryTypesList'] })
  async queryTypes(params) {
    var list: any = await (servers as any)
      .queryTypes({ data: params }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { queryTypesList: list }
  }

  //下拉框报警状态
  @MutationAction({ mutate: ['queryAlermStatusList'] })
  async queryAlermStatus() {
    var list: any = await (servers as any)
      .queryAlermStatus({ data: {} }).then((res: any) => {
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { queryAlermStatusList: list }
  }

  //下拉框所属地市
  @MutationAction({ mutate: ['queryCitysList'] })
  async queryCitys() {
    var list: any = await (servers as any)
      .queryCitys({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { queryCitysList: list }
  }
  //下拉框所属系统
  @MutationAction({ mutate: ['querySystemsList'] })
  async querySystems() {
    var list: any = await (servers as any)
      .querySystems({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { querySystemsList: list }
  }
  //获取子系统名称
  @MutationAction({ mutate: ['querySubSystemList'] })
  async querySubSystem() {
    var list: any = await (servers as any)
      .querySubSystem({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    //  console.log(list);
    return { querySubSystemList: list }
  }
  //下拉框有数据变电站
  @MutationAction({ mutate: ['queryHasDataStationsList'] })
  async queryHasDataStations(type) {


    var list: any = await (servers as any)
      .queryHasDataStations({ data: { type } }).then((res: any) => {
        // .queryHasDataStations({ data: {} }).then((res: any) => {
        // console.log(res.data);
        if (res.data) {
          return res.data
        }
      })
      .catch((err: object) => {
        console.log(err);
      });
    // console.log(list);
    return { queryHasDataStationsList: list }
  }

}

export const publicAPIModule = getModule(publicAPI);
